package com.jdrx.sw.sewage.service;

import com.google.common.collect.Maps;
import com.jdrx.sw.sewage.beans.vo.AiForecastVO;
import com.jdrx.sw.sewage.beans.vo.AiForecastWeeklyVO;
import com.jdrx.sw.sewage.dao.AiForecastDAO;
import com.jdrx.sw.sewage.service.base.BaseServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class AiForecastServiceImpl extends BaseServiceImpl {

    public static final Logger logger = LoggerFactory.getLogger(AiForecastServiceImpl.class);

    @Autowired
    private AiForecastDAO aiForecastDAO;

    public Map<String, List<AiForecastVO>> findCarbonSourceForecast(String parentName) {
        List<AiForecastVO> lists = aiForecastDAO.findCarbonSourceForecast(parentName);
        if (null == lists || lists.size() <= 0) return Maps.newHashMap();
        return lists.stream().collect(Collectors.groupingByConcurrent(AiForecastVO::getModelName));
    }

    public Map<String, List<AiForecastVO>> findWeekCarbonSourceForecast(LocalDateTime crTime, String parentName) {
        List<AiForecastVO> lists = aiForecastDAO.findWeekCarbonSourceForecast(crTime, parentName);
        if (null == lists || lists.size() <= 0) return Maps.newHashMap();
        return lists.stream().collect(Collectors.groupingByConcurrent(AiForecastVO::getModelName));
    }

    public AiForecastWeeklyVO findConclusion(String parentName) {
        return aiForecastDAO.findConclusion(parentName);
    }

    public Double findElectricQuantity(String startTime, String endTime) {
        return aiForecastDAO.findElectricQuantity(startTime, endTime);
    }
}
